<?php

/* 会员 member */
class FactoryModel extends BaseModel
{
    var $table  = 'factory';
    var $prikey = 'factory_id';
    var $_name  = 'factory';
	
    var $_relation = array(
		'belongs_type' => array(
            'model'         => 'factorytype',
            'type'          => BELONGS_TO,
            'foreign_key'   => 'type_id',
            'reverse'       => 'has_factory',
        ),
		'has_sample' => array(
			'model' => 'sample',
			'type' => HAS_MANY,
			'foreign_key' => 'factory_id',
		),
	);

    /*
     * 判断名称是否唯一
     */
    function unique($factory_name, $factory_id = 0)
    {
        $conditions = "factory_name = '" . $factory_name . "'";
        $factory_id && $conditions .= " AND factory_id <> '" . $factory_id . "'";
        return count($this->find(array('conditions' => $conditions))) == 0;
    }
}

?>